package com.bestow.dox4j.utils;

import org.apache.commons.lang3.StringUtils;

public class SqlUtils {

    public static String toMySQL(String oldSql) {
        if (StringUtils.isEmpty(oldSql)) {
            return oldSql;
        }
        return oldSql.replaceAll("(?i)\\bnvl\\b", "ifnull")
                .replaceAll("(?i)\\bwm_concat\\b","group_concat")
                .replaceAll("(?i)\\bto_char\\b","");
    }

    public static String toOracle(String oldSql) {
        if (StringUtils.isEmpty(oldSql)) {
            return oldSql;
        }
        oldSql = oldSql.replaceAll("(?i)\\bifnull\\b", "nvl")
                .replaceAll("(?i)\\blimit\\s1\\b", "and rownum = 1")
                .replaceAll("(?i)\\belse\\s+''", "else null")
                .replaceAll("(?i)\\blcase\\b", "lower")
                .replaceAll("(?i)\\blimit\\s+0,\\s+1", "and rownum = 1")
                .replaceAll("(?i)\\b\"\\b", "'")
                .replaceAll("(?i)\\bgroup_concat\\b", "wm_concat");
        return oldSql;
    }
}
